/*************************************************************************
	> File Name: user.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年11月29日 星期一 20时56分57秒
 ************************************************************************/

#include<iostream>
#include <string>

class User
{
public:
	User() = default;
	User(int value, std::string n) : _id(value), name(n) {}
	
	int getId()
	{
		return _id;
	}

	void setId(int value)
	{
		_id = value;
	}

	std::string getName()
	{
		return name;
	}

	void setName(std::string n)
	{
		name = n;
	}

private:
	int _id;
	std::string name;
};

class IUser
{
public:
	virtual void insert(User user) = 0;
	virtual User getUser(int id) = 0;
};

class SqlserverUser : public IUser
{
public:
	virtual void insert(User user)
	{
		std::cout << "在SQL Server中给User表增加一个记录" << std::endl; 
	}

	virtual User getUser(int id)
	{
		std::cout << "在SQL Server中根据ID得到User表的一个记录" << std::endl;
		return User();
	}
};

class AccessUser : public IUser
{
public:
	virtual void insert(User user)
	{
		std::cout << "在Access中给User表增加一个记录" << std::endl;
	}

	virtual User getUser(int id)
	{
		std::cout << "在Access中根据ID得到User表中的一个记录" << std::endl;
		return User();
	}
};

struct IFactory
{
	virtual IUser* createUser() = 0;
};

struct SqlserverFactory : public IFactory
{
	virtual IUser* createUser()
	{
		return new SqlserverUser();
	}
};

struct AccessFactory : public IFactory
{
	virtual IUser* createUser()
	{
		return new AccessUser();
	}
};
